A PHP design pattern for the model part [PHP Zend Framework]
Posted
by Matthieu
on Stack Overflow
See other posts from Stack Overflow
or by Matthieu
Published on 2010-03-23T10:38:11Z
Indexed on
2010/03/23
10:43 UTC
Read the original article
Hit count: 517
I have a PHP MVC application using Zend Framework. As presented in the quickstart, I use 3 layers for the model part :
- Model (business logic)
- Data mapper
- Table data gateway (or data access object, i.e. one class per SQL table)
The model is UML designed and totally independent of the DB.
My problem is : I can't have multiple instances of the same "instance/record".
For example : if I get, for example, the user "Chuck Norris" with id=5, this will create a new model instance wich members will be filled by the data mapper (the data mapper query the table data gateway that query the DB). Then, if I change the name to "Duck Norras", don't save it in DB right away, and re-load the same user in another variable, I have "synchronisation" problems... (different instances for the same "record")
Right now, I use the Multiton pattern : like Singleton, but multiple instances indexed by a key (wich is the user ID in our example). But this is complicating my developpement a lot, and my testings too.
How to do it right ?
© Stack Overflow or respective owner